package com.chester.springbootseventeen.controller;


import com.alibaba.fastjson.JSONObject;
import com.chester.springbootseventeen.config.exception.IllegalPropertiesException;
import com.chester.springbootseventeen.config.exception.NullOrEmptyException;
import com.chester.springbootseventeen.service.impl.StudentServiceImpl;
import com.chester.springbootseventeen.utils.ResultMessage;
import com.chester.springbootseventeen.utils.ResultUtils;
import com.cxytiandi.encrypt.anno.Decrypt;
import com.cxytiandi.encrypt.anno.Encrypt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author chester7cheng
 * @since 2018-10-02
 */
@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentServiceImpl studentService;

    @Encrypt
    @GetMapping("/all")
    public ResultMessage all(@RequestParam Map param) {
        List studentList = studentService.list(null);
        return ResultUtils.succeed(studentList);
    }

    @Decrypt
    @PostMapping("/update")
    public ResultMessage update(@RequestBody JSONObject param) {
        return ResultUtils.succeed(null);
    }

    @PostMapping("/exception")
    public ResultMessage exception(@RequestBody JSONObject param) throws NullOrEmptyException, IllegalPropertiesException {
//        throw new SessionNotFoundException();
        throw new NullOrEmptyException();
//        throw new IllegalPropertiesException("username");
//        throw new IllegalPropertiesException("accountName");

    }
}
